package com.zwj.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zwj.dto.EnumResult;
import com.zwj.dto.Result;
import com.zwj.entity.CourseIndustryEntity;
import com.zwj.entity.CourseTypeEntity;
import com.zwj.enums.IsDeletedEnum;
import com.zwj.enums.RoleEnum;
import com.zwj.enums.SexEnum;
import com.zwj.enums.StatusEnum;
import com.zwj.mapper.CommonMapper;
import com.zwj.mapper.CourseIndustryMapper;
import com.zwj.mapper.CourseTypeMapper;
import com.zwj.mapper.UserRoleMapper;
import com.zwj.service.CommonService;
import com.zwj.service.CourseTypeService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


@Service
public class CommonServiceImpl implements CommonService {
    private final CommonMapper commonMapper;
    private final CourseIndustryMapper courseIndustryMapper;
    private final CourseTypeMapper courseTypeMapper;
    public CommonServiceImpl(CommonMapper commonMapper,CourseIndustryMapper courseIndustryMapper,CourseTypeMapper courseTypeMapper) {
        this.commonMapper = commonMapper;
        this.courseIndustryMapper = courseIndustryMapper;
        this.courseTypeMapper = courseTypeMapper;
    }
    @Override
    public Result getStatus() {
        return Result.ok().data(StatusEnum.getEnumList());
    }

    @Override
    public Result getSex() {
        return Result.ok().data(SexEnum.getEnumList());
    }

    @Override
    public Result getRole() {
        return Result.ok().data(RoleEnum.getEnumList());
    }

    @Override
    public Result getIndustry() {
        QueryWrapper<CourseIndustryEntity> sectionQueryWrapper = new QueryWrapper<>();
        sectionQueryWrapper.lambda().eq(CourseIndustryEntity::getIsDeleted, IsDeletedEnum.NO.getKey()).select(CourseIndustryEntity::getId,CourseIndustryEntity::getName);
        List<CourseIndustryEntity> courseIndustryEntities = courseIndustryMapper.selectList(sectionQueryWrapper);
        if (courseIndustryEntities.size() == 0) {
            return Result.error().message("没有有效班级");
        }
        List<EnumResult> result = courseIndustryEntities.stream().map(
                entry -> new EnumResult(entry.getId(), entry.getName())).collect(Collectors.toList());
        return Result.ok().data(result);
    }

    @Override
    public Result getType() {
        QueryWrapper<CourseTypeEntity> sectionQueryWrapper = new QueryWrapper<>();
        sectionQueryWrapper.lambda().eq(CourseTypeEntity::getIsDeleted, IsDeletedEnum.NO.getKey()).select(CourseTypeEntity::getId,CourseTypeEntity::getName);
        List<CourseTypeEntity> courseTypeEntities = courseTypeMapper.selectList(sectionQueryWrapper);
        if (courseTypeEntities.size() == 0) {
            return Result.error().message("没有有效班级");
        }
        List<EnumResult> result = courseTypeEntities.stream().map(
                entry -> new EnumResult(entry.getId(), entry.getName())).collect(Collectors.toList());
        return Result.ok().data(result);
    }

}
